<template>
	<view class="container-8989" @touchmove.stop.prevent>
		<view class="container-566"></view>
		<view class="content-12" ref="comtemt">
			<view class="title-box">
				<!-- <view class="imgview">取消</view> -->
				<view class="item">
					<view class="text">选择时间</view>
				</view>
				<image @focus="inputBindFocus" class="image-close" src="../static/image/close1.png" mode=""
					@click.stop="handleClose">
				</image>
			</view>
			<view class="content-add-uniapp">
				<view class="choose">
					<view class="cancel" @click.stop="handleClose">
						取消
					</view>
					<view class="confirm" @click.stop="confirm">
						确定
					</view>

				</view>
				<picker-view immediate-change :indicator-style="`${'height:40'}px`" :value="value" @change="bindChange"
					class="picker-view">
					<picker-view-column>
						<view class="item" v-for="(item,index) in years" :key="index">{{item}}年</view>
					</picker-view-column>
					<picker-view-column>
						<view class="item" v-for="(item,index) in months"  :key="index">{{item}}月</view>
					</picker-view-column>
				</picker-view>
			</view>
		</view>
	</view>
</template>
<script>
	export default {
		props: {
			index: {
				type: [Number],
			},
			date: {
				type: String
			},
			storeRow: {
				type: Object
			},
			pickerData: {
				type: Object
			}
		},
		data() {

			return {
				years: [],
				months: [],
				year: [],
				month: [],
				_date: "",
				value: [0, 0],
				yearColumn: '',
				monthColumn: 0,
				yearIndex: 0,
				monthIndex: '',
				dataList: [],
				_storeRow: null
			};
		},

		mounted() {
			this._storeRow = this.storeRow
			this._date = this.date;
			this.years = this.pickerData.yearList;
			this.dataList = this.pickerData.dataList;
			this.yearColumn = this._date.split('-')[0]
			this.monthColumn = this._date.split('-')[1]
			this.yearIndex = this.years.findIndex((item, index) => {
				return item == this.yearColumn
			})
			let data = this.dataList.filter(item => {
				if (item.year == this.years[this.yearIndex]) {
					return item
				}
			})
			let _data = data.map(item => {
				return item.month
			})
			this.monthIndex = _data.findIndex(item => {
				return item == this.monthColumn
			})

			this.months = [..._data]

			this.$nextTick(() => {
				this.value = [this.yearIndex, this.monthIndex]
				// console.log(this.value, '556565566')
			})
		},

		destroyed() {
			this.years = [];
			this.months = [];
			this.year = [];
			this.month = [];
			this._date = "";
			this.value = [0, 0];
			this.yearColumn = '';
			this.monthColumn = 0;
			this.yearIndex = 0;
			this.monthIndex = '';
			this.dataList = [];
			this._storeRow = null
		},
		methods: {
			// 处理数据
			handlerMonth(year, index,val) {
				let data = this.dataList.filter(item => {
					if (item.year == year) {
						return item
					}
				});
				let _data = data.map(item => {
					return item.month
				});
				this.months = [..._data];
				this.$nextTick(() => {
					this.value = [index, 0];
					this.month = this.months[this.value[1]];
					// console.log(this.value, "--🔥🔥----", this.month, this.months,val)
				});
			},
			bindChange(e) {
				const val = e.detail.value;
				console.log(e,"---eee--")
				this.$nextTick(async () => {
					this.year = this.years[val[0]];
					// 处理月
					await this.handlerMonth(this.year, val[0],val);

					this.value = val;
					// console.log(this.value, "--🎉🎉🎉----", this.month, this.months);


				})
			},
			handleClose() {
				this.$emit('close');
			},
			confirm() {
				// console.log(this.months,'',this.value)
				this.$emit('confirm', {
					month: `${ this.years[this.value[0]]}-${this.months[this.value[1]]}`,
					storeCode: this.storeRow.code
				});
			},
		}
	};
</script>

<style lang="scss" scoped>
	.container-8989 {
		width: 100%;
		height: 100vh;
		display: flex;
		align-items: flex-end;
		// background: rgba(0, 0, 0, 0.7);
		position: fixed;
		left: 0;
		top: 0;
		z-index: 1000;

		.picker-view {
			width: 100%;
			height: 400rpx;
			margin-top: 20rpx;
		}

		.item {
			line-height: 80rpx;
			text-align: center;
		}

		.container-566 {
			position: absolute;
			height: 100%;
			width: 100%;
			background-color: rgba(0, 0, 0, .5);
			z-index: 50;
		}

		.klsadkl {
			display: flex;
			flex-direction: column;
			// justify-content: center;
			padding-top: 10%;
			align-items: center;
			min-height: 28vh;

			.store-img-empty {
				width: 160rpx;
				height: 160rpx;
			}

			.dsa-empty-content {
				height: 40rpx;
				font-size: 24rpx;
				color: #666666;
			}
		}



		.store-item-content {
			max-height: 46vh;
			// border: 2rpx solid;
			background: #ffffff;
			margin-top: 20rpx;
			margin-bottom: 65Px;
			border-radius: 16rpx;

			.store-item {
				box-sizing: border-box;
				display: flex;
				align-items: center;
				padding: 16rpx;

				.store-info {
					height: 100%;
					flex: 1;
					font-size: 24rpx;
					line-height: 40rpx;

					.name {
						font-size: 28rpx;
						// font-weight: 600;
					}

					.address {
						margin-left: 10rpx;
					}

					.store-address {
						color: #999;
						// margin-top: 20rpx;
					}

					.time {
						color: #666;
					}

					.distance {
						margin-top: 4rpx;
					}
				}

				.right {
					width: 100%;
					height: 100%;
					display: flex;
					align-items: center;

					// border-bottom: 2rpx solid #f1f1f1;
					.select-btn {
						width: 44rpx;
						min-width: 44rpx;
						height: 44rpx;
						border-radius: center;
						border: 2rpx solid #e4e4e4;
						border-radius: 50%;
						margin-left: 40rpx;

						&.active {
							display: flex;
							justify-content: center;
							align-items: center;
							border: none;
							background-color: #1973f7;

							&:before {
								content: '';
								width: 8rpx;
								height: 18rpx;
								border-right: 2rpx solid #FFFFFF;
								border-bottom: 2rpx solid #FFFFFF;
								transform: rotate(45deg) translate(-2rpx);
							}
						}
					}
				}
			}

			.store-item+.store-item {
				margin-top: 18rpx;
			}
		}


		.class-next {
			background-color: #FFFFFF;
		}

		.class-footer {
			position: absolute;
			width: 100%;
			height: 108rpx;
			// bottom: constant(safe-area-inset-bottom);
			bottom: 40rpx;
			display: flex;
			align-items: center;
			justify-content: center;

			view.envent-no {
				opacity: 0.5;
			}

			.inset-bottom-content {
				width: 626rpx;
				height: 76rpx;
				background-color: #1973f7;

				border-radius: 200rpx;
				display: flex;
				align-items: center;
				justify-content: center;

				.confirm {
					font-weight: 500;
					font-size: 30rpx;
					line-height: 40rpx;
					text-align: center;
					color: #FFFFFF;
				}
			}

		}

		.content-12 {
			width: 100%;
			border-radius: 16rpx 16rpx 0 0;
			background-color: #fff;
			// height: 1062rpx;
			position: absolute;

			z-index: 51;
			// border: 2rpx solid;
			// right: -100%;
			padding-bottom: constant(safe-area-inset-bottom);
			padding-bottom: env(safe-area-inset-bottom);

			.content-add-uniapp {
				height: 100%;
				padding: 0 24rpx;
				height: 35vh;

				.choose {
					display: flex;
					justify-content: space-between;
					align-items: center;
					padding: 0 24rpx;
					height: 80rpx;
					font-weight: 400;
					font-size: 32rpx;
					border-bottom: 1rpx solid #E7E7E7;
					color: #999999;

					.confirm {
						color: #1973F7;
					}
				}

			}

			.imgview {
				display: flex;
				align-items: center;
				justify-content: center;
				height: 48rpx;
			}
		}

		.title-box {
			display: flex;
			justify-content: space-between;
			padding: 24rpx;
			flex: 1;
			align-items: center;

			.image-close {
				width: 36rpx;
				height: 36rpx;
				vertical-align: middle;
			}

			.item {
				width: 100%;
				display: flex;
				justify-content: center;
				align-items: center;
				font-weight: 550;
				font-size: 36rpx;
				line-height: 56rpx;
				text-align: center;
				color: #333333;

				.acyive-imga-01 {
					background-position: 100% 100%;
					background-repeat: no-repeat;
					background-size: 100%;
				}
			}
		}


		.content {
			width: 100%;
			border-radius: 16rpx 16rpx 0 0;
			background-color: #f5f5f5;
			height: 1062rpx;
			position: relative;
			transform: translateX(0%);
			transition: transform ease .3s;
			padding-bottom: constant(safe-area-inset-bottom);
			padding-bottom: env(safe-area-inset-bottom);
		}
	}
</style>